/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package service;

import dao.ExampaperDao;
import dao.ExamquestionDao;
import entity.Exampaper;
import entity.Examquestion;
import entity.bean.Examquestions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class ExamService {

	@Resource
	private ExampaperDao exampaperDao;

	@Resource
	private ExamquestionDao examquestionDao;

	public void savePaper(Exampaper exampaper, Examquestions examquestions) {
		this.exampaperDao.save(exampaper);
		Long paperid = exampaper.getId();
		for (Examquestion e : examquestions.getExamquestion()) {
			e.setPaperid(paperid);
		}
		this.examquestionDao.save(examquestions.getExamquestion());
	}

	public Exampaper getPaperByPaperId(Long paperid) {
		Map map = new HashMap();
		map.put("id", paperid);
		return ((Exampaper) this.exampaperDao.get(
				"from Exampaper where id=:id", map));
	}

	public List<Exampaper> getPapers() {
		return this.exampaperDao.find("from Exampaper");
	}

	public List<Examquestion> getQuestByPaperId(Long paperid) {
		Map map = new HashMap();
		map.put("paperid", paperid);
		return this.examquestionDao.find(
				"from Examquestion where paperid=:paperid", map);
	}
}